package com.xju.controller.book;

import com.xju.common.utils.PageInfo;
import com.xju.entity.Books;
import com.xju.service.BookService;
import com.xju.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import java.io.IOException;

@WebServlet("/book/list")
public class BookListServlet extends HttpServlet {

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        //pageNo pageSize
        //获取参数
        req.setCharacterEncoding("utf-8");
        String pageNoStr = req.getParameter("pageNo");
        String pageSizeStr = req.getParameter("pageSize");
        String key = req.getParameter("key");
        
        //判断
        int pageNo = pageNoStr == null || pageNoStr.trim().isEmpty()? 1 : Integer.parseInt(pageNoStr);
        int pageSize = pageSizeStr == null || pageSizeStr.trim().isEmpty()? 5 : Integer.parseInt(pageSizeStr);

        //调用service
        BookService bookService=new BookServiceImpl();
        PageInfo<Books>PageInfo =  bookService.pageList(pageNo,pageSize,key);
        req.setAttribute("PageInfo", PageInfo);
        req.getRequestDispatcher("/pages/book/list.jsp").forward(req, res);
    }
}








